package com.wuh.service.impl;

import java.util.Date;
import java.util.List;

import com.wuh.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wuh.mapper.CastleMapper;
import com.wuh.model.CastleAtta;
import com.wuh.model.CastleCollect;
import com.wuh.model.CastleComment;
import com.wuh.model.CastleInfo;
import com.wuh.model.CastleSignup;
import com.wuh.model.CastleType;
import com.wuh.model.MallType;
import com.wuh.model.TeacherPhrase;
import com.wuh.service.CastleService;

@Service
public class CastleServiceImpl implements CastleService {

	@Autowired
	private CastleMapper castleMapper;

	@Override
	public PageInfo<CastleInfo> getCastleInfos(CastleInfo castleInfo) {
		PageHelper.startPage(castleInfo.getPageNum(), castleInfo.getPageSize());
		List<CastleInfo> list = castleMapper.getCastleInfos(castleInfo);
		PageInfo<CastleInfo> pageInfo = new PageInfo<CastleInfo>(list);
		return pageInfo;
	}

	@Override
	public CastleInfo getCastleInfoById(Integer castle_id) {

		return castleMapper.getCastleInfoById(castle_id);
	}

	@Override
	public List<CastleType> getCastleTypes() {
		
		return castleMapper.getCastleTypes();
	}

	@Override
	public List<MallType> getMallTypes() {
		
		return castleMapper.getMallTypes();
	}

	@Override
	public void addCastle(CastleInfo castleInfo) {
		
		castleInfo.setSignup_num(0);
		castleInfo.setCollect_num(0);
		castleInfo.setComment_num(0);
		castleInfo.setLast_modify(new Date());
		
		castleMapper.addCastle(castleInfo);
	}

	@Override
	public void addAtta(CastleAtta castleAtta) {
		
		castleMapper.addAtta(castleAtta);
	}

	@Override
	public void addSignup(CastleSignup castleSignup) {
		
		castleSignup.setLast_modify(new Date());
		castleMapper.addSignup(castleSignup);
	}

	@Override
	public void editCastle(CastleInfo castleInfo) {
		
		castleInfo.setLast_modify(new Date());
		castleMapper.editCastle(castleInfo);
	}

	@Override
	public List<CastleAtta> getAttas(Integer castle_id) {
		
		return castleMapper.getAttas(castle_id);
	}

	@Override
	public void delCastle(Integer castle_id) {
		
		castleMapper.delCastle(castle_id);
	}

	@Override
	public void delAttas(Integer castle_id) {
		
		castleMapper.delAttas(castle_id);
	}

	@Override
	public void delSignup(CastleSignup castleSignup) {
		
		castleMapper.delSignup(castleSignup);
	}

	@Override
	public CastleAtta getAttaById(Integer attachment_id) {
		
		return castleMapper.getAttaById(attachment_id);
	}

	@Override
	public List<CastleInfo> getCastleInfoLimit() {
		
		return castleMapper.getCastleInfoLimit();
	}

	@Override
	public List<CastleComment> getCastleComments(Integer castle_id) {
		
		return castleMapper.getCastleComments(castle_id);
	}

	@Override
	public void addCollect(CastleCollect castleCollect) {
		
		castleCollect.setLast_modify(new Date());
		castleMapper.addCollect(castleCollect);
	}

	@Override
	public void delCollect(CastleCollect castleCollect) {
		
		castleMapper.delCollect(castleCollect);
	}

	@Override
	public CastleCollect getCastleCollect(CastleCollect castleCollect) {
		
		return castleMapper.getCastleCollect(castleCollect);
	}

	@Override
	public void addComment1(CastleComment castleComment) {
		
		castleComment.setLast_modify(new Date());
		castleMapper.addComment1(castleComment);
	}

	@Override
	public void delComment(Integer coment_id) {
	
		castleMapper.delComment(coment_id);
	}

	@Override
	public void editComment(CastleComment castleComment) {
		
		castleComment.setLast_modify(new Date());
		castleMapper.editComment(castleComment);
	}

	@Override
	public List<Integer> getCastleIdByGroup(Integer gid) {
		return castleMapper.getCastleIdByGroup(gid);
	}

	@Override
	public void updatecastleId(CastleInfo castleInfor) {
		castleMapper.updatecastleId(castleInfor);
	}

	@Override
	public PageInfo<CastleSignup> getSignups(CastleSignup castleSignup) {
		PageHelper.startPage(castleSignup.getCastleInfo().getPageNum(), castleSignup.getCastleInfo().getPageSize());
		List<CastleSignup> list = castleMapper.getSignups(castleSignup);
		PageInfo<CastleSignup> pageInfo = new PageInfo<CastleSignup>(list);
		return pageInfo;
	}

	@Override
	@Transactional
	public void closeCastles(Integer[] ids) {
		for(Integer id : ids) {
			castleMapper.closeCastle(id);
		}
	}

	@Override
	@Transactional
	public void refreshCastles(Integer[] ids) {
		for(Integer id : ids) {
			castleMapper.refreshCastle(id);
		}
	}

	@Override
	@Transactional
	public void delCastles(Integer[] ids) {
		for(Integer id : ids) {
			castleMapper.delCastle(id);
		}
	}

	@Override
	public CastleSignup getSignup(CastleSignup castleSignup) {

		return castleMapper.getSignup(castleSignup);
	}

	@Override
	public void addTeacherPhrase(TeacherPhrase teacherPhrase) {
		teacherPhrase.setLast_modify(new Date());
		castleMapper.addTeacherPhrase(teacherPhrase);
	}

	@Override
	public void delTeacherPhrase(TeacherPhrase teacherPhrase) {

		castleMapper.delTeacherPhrase(teacherPhrase);
	}

	@Override
	public List<TeacherPhrase> getTeacherPhraseByUserId(Integer user_id) {

		return castleMapper.getTeacherPhraseByUserId(user_id);
	}


}
